import axios from '@/axios'

// 获取用户信息
export function apiGetUser(id) {
  const params = {}
  if (id) params.testOAuthUser = id
  return axios.get('projectNodeReview/review/getUser', {params})
}

// 删除节点
export function apiDelete(userID, id) {
  if (userID) {
    return axios.get('projectNodeReview/review/delet?testOAuthUser=' + userID + '&id=' + id)
  } else {
    return axios.get('projectNodeReview/review/delet?id=' + id)
  }
}

// 获取节点列表
export function apiGetList(userID, status, form) {
  if (userID) {
    return axios.post(
      'projectNodeReview/review/listPage?testOAuthUser=' + userID,
      {
        status: status,
        ...form
      }
    )
  } else {
    return axios.post(
      'projectNodeReview/review/listPage',
      {
        status: status,
        ...form
      }
    )
  }
}

// 获取项目
export function apiGetUserProject(userID, val) {
  if (userID) {
    return axios.post('projectNodeReview/review/getUserProject?testOAuthUser=' + userID, {
      projectName: val
    })
  } else {
    return axios.post('projectNodeReview/review/getUserProject', {
      projectName: val
    })
  }
}

// 获取合同
export function apiGetPMContractInfo(userID, projectCode, projectCompany, val) {
  if (userID) {
    return axios.get('projectNodeReview/review/getPMContractInfo', {
      params: {
        testOAuthUser: userID,
        projectCode: projectCode,
        projectCompany: projectCompany,
        contractname: val
      }
    })
  } else {
    return axios.get('projectNodeReview/review/getPMContractInfo', {
      params: {
        projectCode: projectCode,
        projectCompany: projectCompany,
        contractname: val
      }
    })
  }
}

// 获取支付节点
export function apiGetPayNodeList(userID, projectCode, contractCode, val, company, contractId) {
  if (userID) {
    return axios.get('projectNodeReview/review/getPayNodeList', {
      params: {
        testOAuthUser: userID,
        projectCode: projectCode,
        contractCode: contractCode,
        nodeName: val,
        projectCompany: company,
        contractId: contractId
      }
    })
  } else {
    return axios.get('projectNodeReview/review/getPayNodeList', {
      params: {
        projectCode: projectCode,
        contractCode: contractCode,
        nodeName: val,
        projectCompany: company,
        contractId: contractId
      }
    })
  }
}

// 获取楼栋
export function apiGetBuilingList(userID, projectCode, contractCode, DUIXIANGID) {
  if (userID) {
    return axios.get('projectNodeReview/review/getBuilingList', {
      params: {
        testOAuthUser: userID,
        projectCode: projectCode,
        contractCode: contractCode,
        objectId: DUIXIANGID
      }
    })
  } else {
    return axios.get('projectNodeReview/review/getBuilingList', {
      params: {
        projectCode: projectCode,
        contractCode: contractCode,
        objectId: DUIXIANGID
      }
    })
  }
}

// 获取分包合同种类
export function apiGetSubpackageList(userID, FANBENBIANHAO) {
  if (userID) {
    return axios.get('projectNodeReview/review/getSubpackageList', {
      params: {
        testOAuthUser: userID,
        FANBENBIANHAO: FANBENBIANHAO
      }
    })
  } else {
    return axios.get('projectNodeReview/review/getSubpackageList', {
      params: {
        FANBENBIANHAO: FANBENBIANHAO
      }
    })
  }
}

// 获取详情
export function apiGetDetail(userID, addedID) {
  if (userID) {
    return axios.get('projectNodeReview/review/detial', {
      params: {
        testOAuthUser: userID,
        id: addedID
      }
    })
  } else {
    return axios.get('projectNodeReview/review/detial', {
      params: {
        id: addedID
      }
    })
  }
}

// 提交基本信息
export function apiPostBaseInfo(userID, form) {
  if (userID) {
    return axios.post('projectNodeReview/review/save?testOAuthUser=' + userID, form)
  } else {
    return axios.post('projectNodeReview/review/save', form)
  }
}

// 确认验收
export function apiConfirmYS(userID, addedID) {
  if (userID) {
    return axios.get('projectNodeReview/review/sendFlow?id=' + addedID + '&testOAuthUser=' + userID)
  } else {
    return axios.get('projectNodeReview/review/sendFlow?id=' + addedID)
  }
}

// 设置其他完成率
export function apiSetItems(userID, sData) {
  if (userID) {
    return axios.post('projectNodeReview/review/update/items?testOAuthUser='+ userID, sData)
  } else {
    return axios.post('projectNodeReview/review/update/items', sData)
  }
}

// 获取文件信息
export function apiGetFileInfo(userID, code) {
  if (userID) {
    return axios.get('projectNodeReview/review/viewFile?fileCode=' + code + '&testOAuthUser=' + userID)
  } else {
    return axios.get('projectNodeReview/review/viewFile?fileCode=' + code)
  }
}

// 更新数据
export function apiUpdate(userID, subData) {
  if (userID) {
    return axios.post('projectNodeReview/review/update?testOAuthUser=' + userID, subData)
  } else {
    return axios.post('projectNodeReview/review/update', subData)
  }
}

// 获取上传码
export function apiGetUploadCode(userID) {
  if (userID) {
    return axios.get('projectNodeReview/review/getUploadCode', {
      params: {
        testOAuthUser: userID
      }
    })
  } else {
    return axios.get('projectNodeReview/review/getUploadCode')
  }
}

// 上传base64
export function apiUploadBase(userID, code, result, fileName) {
  if (userID) {
    return axios.post('mobileAttachment/uploadBase?module=proNodeReivew&activity=true&code=' + code + '&testOAuthUser=' + userID + '&fileName=' + fileName, {
      'base': result
    })
  } else {
    return axios.post('mobileAttachment/uploadBase?module=proNodeReivew&activity=true&code=' + code + '&fileName=' + fileName, {
      'base': result
    })
  }
}

// 获取审批流程
export function apiGetWorkflow(userID, instanceID) {
  if (userID) {
    return axios.get('workflow/imgInfo/instanceinfo?testOAuthUser=' + userID + '&instanceId=' + instanceID)
  } else {
    return axios.get('workflow/imgInfo/instanceinfo?instanceId=' + instanceID)
  }
}

// 获取责任合同单位
export function apiGetContractCompanyList(userID, projectCode, contractCode, nodeName, projectCompany) {
  if (userID) {
    return axios.get('projectNodeReview/review/getContractCompanyList?testOAuthUser=' + userID
        + '&projectCode=' + projectCode
        + '&contractCode=' + contractCode
        + '&nodeName=' + nodeName
        + '&projectCompany=' + projectCompany)
  } else {
    return axios.get('projectNodeReview/review/getContractCompanyList'
        + '?projectCode=' + projectCode
        + '&contractCode=' + contractCode
        + '&nodeName=' + nodeName
        + '&projectCompany=' + projectCompany)
  }
}